package com.neusoft.yuejian26.yuejian_26.Activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.neusoft.yuejian26.yuejian_26.Bean.Userbean;
import com.neusoft.yuejian26.yuejian_26.Other.CacheInfo;
import com.neusoft.yuejian26.yuejian_26.R;
import com.neusoft.yuejian26.yuejian_26.model.UserModel;
import com.neusoft.yuejian26.yuejian_26.network.RetrofitCallback;
import com.squareup.picasso.Picasso;

import de.hdodenhof.circleimageview.CircleImageView;
import retrofit2.Call;

public class UserIntroActivity extends AppCompatActivity {

    public CircleImageView intro_pic;
    public LinearLayout intro_pic_me,intro_name_me,intro_tel_me,qr_me;
    public TextView intro_name,intro_tel;
    public ImageView svg_back;
    private String uid=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_intro);
        intview();
        intEvent();
        getUserIntroData();
    }

    private void getUserIntroData(){
        uid=new CacheInfo(UserIntroActivity.this).getUserIdCache();
        if(uid!=null) {
            UserModel userModel = new UserModel();
            Call call = userModel.userIntro(uid);
            userModel.bindCallback(call, new RetrofitCallback() {
                @Override
                public void onResponse(Object o) {
                    Userbean userintrodata = (Userbean) o;
                    Picasso.with(UserIntroActivity.this).load("http://115.159.93.244/new18yuejian/Public/upload/" + userintrodata.getUserpic()).into(intro_pic);
                    intro_name.setText(userintrodata.getUname());
                    intro_tel.setText(userintrodata.getUtel());
                }
            });
        }
    }

    private void intview(){
        intro_pic_me=(LinearLayout) findViewById(R.id.intro_pic_me);
        intro_pic=(CircleImageView) findViewById(R.id.intro_pic);
        intro_name_me=(LinearLayout)findViewById(R.id.intro_name_me);
        intro_tel_me=(LinearLayout)findViewById(R.id.intro_tel_me);
        qr_me= (LinearLayout) findViewById(R.id.qr_me);
        intro_name=(TextView) findViewById(R.id.intro_name);
        intro_tel=(TextView) findViewById(R.id.intro_tel);
        svg_back=(ImageView) findViewById(R.id.svg_back);
    }

    private void intEvent(){
        intro_pic_me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserIntroActivity.this,UserPicSimpActivity.class);
                startActivity(intent);
            }
        });
        intro_name_me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserIntroActivity.this,UserNameSimpActivity.class);
                startActivity(intent);
            }
        });
        intro_tel_me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserIntroActivity.this,UserTelSimpActivity.class);
                startActivity(intent);
            }
        });
        qr_me.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserIntroActivity.this,QRActivity.class);
                startActivity(intent);
            }
        });
        svg_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(UserIntroActivity.this,MainActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("page",4);
                intent.putExtras(bundle);
                startActivity(intent);
                finish();
            }
        });
    }

}
